<?php 
ini_set('date.timezone','Asia/Shanghai');
class dbli{
    /* 数据库链接 */
    public $con;
    /* 构造方法连接数据库 */
    public function __construct($conf) {
        $con=new mysqli( $conf ['DBhost'], $conf ['DBname'], $conf ['DBpasswd'],$conf ['DBbase'],3306);
        mysqli_query($con, 'set names utf8');
        $this->con = $con;
    }

    /* count */
    public function count($sql) {
        $query =mysqli_query($this->con, $sql);
        $result=  mysqli_fetch_array($query);
        return $result [0];
    }

    /* 数据库添加方法 */
    public function add($sql) {
        mysqli_query($this->con, $sql);
        $rc = mysqli_affected_rows($this->con);
        if ($rc > 0) {
            return mysqli_insert_id( $this->con );
        } else {
            return 0;
        }
    }

    /* mysql 查询 */
    public function select($sql) {
        $result =  mysqli_query($this->con, $sql);
        $arr=array();
        while ( $row =@ mysqli_fetch_assoc( $result ) ) {
            $arr [] = $row;
        }
        return $arr;
    }

    /* mysql 增改 */
    public function U_D($sql) {
        $result = mysqli_query($this->con, $sql);
        return mysqli_affected_rows ( $this->con );
    }
    /* 获取mysql 错误 */
    public function error() {
        return $this->con->error;
    }

}

    $array=array(
        /*数据库主机  */
        'DBhost'=>'localhost',
        /*数据库名  */
        'DBbase'=>'weixin',
        /*数据账号名  */
        'DBname'=>'root',
        /* 数据库密码 */
        'DBpasswd'=>'',
    );
    
    $db=new dbli($array);
    //$sql="select issue,numbers,gtime from pks_k where games=1 and gtime<".time()." order by gtime desc limit 0,1";
    $sql="select issue,numbers,gtime from pks_k where issue<1000000000 order by issue desc limit 0,1";
    $arr=$db->select($sql);
   // $arr[0]['issue']=597309;
    //$arr[0]['gtime']=strtotime('2017-01-12 23:57');
   // $arr[0]['numbers']='06,02,08,09,07,03,01,10,04,05';
    
    
   //597309	06,02,08,09,07,03,01,10,04,05	2017-01-12 23:57
    $current=array(
        'qihao' => $arr[0]['issue'],
        'awardTime' =>date('Y-m-d H:i:s',$arr[0]['gtime']),
        'awardNumbers' =>$arr[0]['numbers'],
    );
 //$nowdata=date('Y-m-d',strtotime(date('Y-m-d'))+3600*24)." 09:07:30";

   if(date('H',$arr[0]['gtime'])==23 && date('i',$arr[0]['gtime'])==57){
       $nowdata=date('Y-m-d',(strtotime(date('Y-m-d',$arr[0]['gtime']))+3600*24))." 09:07:30";
        
       $times= strtotime($nowdata);
   }else{
        $times=$arr[0]['gtime']+300;
    }
   // echo $times;
    //print_r(date('Y-m-d H:i:s',$times));  
    $next=array('qihao' =>$arr[0]['issue']+1,
        'awardTime'=>date('Y-m-d H:i:s',time()),
        'awardTimeInterval' =>$times-time()<0?0:$times-time()+15,'delayTimeInterval' =>$times-time()<0?0:$times-time()+15);
    $array=Array('time' => time(),'current' =>$current,'next'=>$next);
    echo json_encode($array);
?>